package com.itheima.service.impl.rocketmq;

import com.itheima.service.MessageService;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * ClassName: MessageServiceRocketmqImpl
 * Description:
 * Date: 2023/03/21 PM 8:25:04
 * <p>
 * project: springboot
 * package: com.itheima.service.impl.rocketmq
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
// @Service
public class MessageServiceRocketmqImpl implements MessageService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送消息
     *
     * @param id {@link String} 订单 id
     */
    @Override
    public void sendMessage(String id) {
        System.out.println("待发送短信的订单已纳入处理队列(rocketmq), id: " + id);
        // rocketMQTemplate.convertAndSend("order_id", id);
        SendCallback callback = new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println("消息发送成功");
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println("消息发送失败！！！！！");
            }
        };
        rocketMQTemplate.asyncSend("order_id", id, callback);
    }

    /**
     * 发送消息
     *
     * @return {@link String}
     */
    @Override
    public String doMessage() {
        return null;
    }
}
